{% extends "./inc/base.html" %}
{% block style %}
<!--<link rel="stylesheet" href="/static/admin/js/zTree/metroStyle/metroStyle.css" type="text/css">-->
<link rel="stylesheet" href="/static/admin/js/zTree/zTreeStyle/zTreeStyle.css" type="text/css">
{% endblock%}
{% block content %}


<!-- -->
<section>
    <div class="container">
<div class="row">
    {#
        <!-- LEFT -->
        {% include "./inc/user_left.html" %}
    #}
        <!-- RIGHT -->
        <div class="col-lg-12 col-md-12 col-sm-12">

            <div class="row">
                <div class="col-lg-2 col-md-2 col-sm-4">
                    <div class="list-group no-radius no-border no-bg m-t-n-xxs m-b-none auto ">
                    <section class="panel panel-success m-b-none padding-0">
                        <header class="panel-heading" style="padding: 5px">

                            <button class="btn btn-default btn-xs" id="expandAllBtn" type="button">展开</button>
                            <button class="btn btn-default btn-xs" id="collapseAllBtn" type="button">折叠</button>
                        </header>
                        <div class="panel-body padding-0">
                            <ul id="tree" class="ztree" data-cate="{{controller.get('cate_id')}}"></ul>
                        </div>
                    </section>

                </div></div>
                <div class="col-lg-10 col-md-10 col-sm-8">
                    <ul class="breadcrumb">
                        <li><a href="/center/index"><i class="fa fa-user"></i> 用户中心</a></li>
                        <li><a href="#"><i class="fa fa-newspaper-o"></i> 内容管理</a></li>

                        <li><a href="/center/publish"><i class="fa fa-pencil-square-o"></i> 在线投稿</a></li>

                        {% for nav in breadcrumb%} {% if cate_id == nav.id %}
                        <li class="active">{{nav.title}} <span class="badge bg-info">{{_total}}</span> {% if allow == 0 %}<span class="label btn-warning">（该分类不允许发布内容）</span>{%
                            endif %}</li>
                        {%else%}
                        <li><a href="/center/publish/index/?cate_id={{nav.id}}"><i class="fa fa-list-ul"></i> {{nav.title}}</a></li>
                        {% endif %} {% endfor %} {%if article.id >0 %}
                        <li> <i class="fa fa-list-ul"></i> {{article.title}} </li>{% endif %}

                    </ul>
                    {%if sort%}

                            <ul class="nav nav-tabs ">
                                {%for val in sort.types%}
                                <li class="{%if controller.get('sortid')|length > 0%}{%if controller.get('sortid')==val.enable%}active{%endif%}{%else%}{%if sort.defaultshow == val.enable%}active{%endif%}{%endif%}">
                                    <a href="/center/publish/index/?pid={{pid}}&cate_id={{cate_id}}&group_id={{group_id}}&sortid={{val.enable}}" > {{val.name}}</a>
                                </li>
                                {%endfor%}
                            </ul>


                            <div class="tab-content table-bordered" style="padding: 0; margin-bottom: 20px; margin-top: -1px">
                                <table class="table table-hover table-condensed m-b-none" style="margin-top: -1px">
                                    <tbody>
                                    {% set typenum = 1%}
                                    {%for val in typevar%}
                                    {%if val.search > 1 and val.available==1%}
                                    <tr  {% if typenum > 3 %} class="type_tr_m"  style="display:none"{%endif%} >
                                        <td style="width: 120px" class="text-right">
                                            {{val.option.title}}:
                                        </td>
                                        <td>
                                            {%if 0 == nsobj[val.option.identifier] or null == nsobj[val.option.identifier]%}
                                            <span style="margin-right: 10px">全部</span>
                                            {%else%}
                                            <a href="/center/publish/index/?pid={{pid}}&cate_id={{cate_id}}&group_id={{group_id}}&sortid={{sortid}}&sortval={{0|sort_url(val.option.identifier,typevar,nsobj)|urlencode}}" class="text-info" style="margin-right: 10px">全部</a>
                                            {%endif%}
                                            {%for v in val.rules %}
                                            {%if v.id|sort_act(nsobj[val.option.identifier])%}
                                            <span style="margin-right: 10px">{{v.name}}{{val.option.unit}}</span>
                                            {%else%}
                                            <a href="/center/publish/index/?pid={{pid}}&cate_id={{cate_id}}&group_id={{group_id}}&sortid={{sortid}}&sortval={{v.id|sort_url(val.option.identifier,typevar,nsobj)|urlencode}}" class="text-info" style="margin-right: 10px">{{v.name}}{{val.option.unit}}</a>
                                            {%endif%}
                                            {%endfor%}

                                            <!--子栏目-->
                                            {%for v in val.rules %}
                                            {%if v.id|sort_act(nsobj[val.option.identifier])%}
                                            {% if v.children%}
                                            <div class="subtsm">

                                                {% for v_ in v.children %}
                                                {%if v_.id|sort_act(nsobj[val.option.identifier])%}
                                                <span style="margin-right: 10px">{{v_.name}}{{val.option.unit}}</span>
                                                {%else%}
                                                <a href="/center/publish/index/?pid={{pid}}&cate_id={{cate_id}}&group_id={{group_id}}&sortid={{sortid}}&sortval={{v_.id|sort_url(val.option.identifier,typevar,nsobj)|urlencode}}" class="text-info" style="margin-right: 10px">{{v_.name}}{{val.option.unit}}</a>
                                                {%endif%}
                                                {% endfor %}
                                            </div>
                                            {%endif%}
                                            {%endif%}
                                            {%endfor%}
                                            <!--子栏目-->
                                            {%for v in val.rules %}
                                            {%if v.id|sort_act(nsobj[val.option.identifier])%}
                                            {% if v.children%}

                                            {% for v_ in v.children %}
                                            {%if v_.id|sort_act(nsobj[val.option.identifier])%}
                                            {% if v_.children%}
                                            <div class="subtsm">
                                                {% for v__ in v_.children %}

                                                {%if v__.id|sort_act(nsobj[val.option.identifier])%}

                                                <span style="margin-right: 10px">{{v__.name}}{{val.option.unit}}</span>
                                                {%else%}
                                                <a href="/center/publish/index/?pid={{pid}}&cate_id={{cate_id}}&group_id={{group_id}}&sortid={{sortid}}&sortval={{v__.id|sort_url(val.option.identifier,typevar,nsobj)|urlencode}}" class="text-info" style="margin-right: 10px">{{v__.name}}{{val.option.unit}}</a>

                                                {%endif%}
                                                {%endfor%}
                                            </div>
                                            {%endif%}
                                            {%endif%}
                                            {% endfor %}

                                            {%endif%}
                                            {%endif%}
                                            {%endfor%}
                                        </td>

                                    </tr>
                                    {% set typenum = typenum+1%}
                                    {%endif%}
                                    {%endfor%}

                                    </tbody>
                                </table>
                                {% if typenum > 4%}
                                <a href="javascript:;" class="center-block btn btn-xs btn-white type_tr_b1" style="border-top: 1px solid #cfd8e1; display: block"><span class="fa fa-chevron-down"></span></a>
                                <a href="javascript:;" class="center-block btn btn-xs btn-white type_tr_b2" style="border-top: 1px solid #cfd8e1; display: none"><span class="fa fa-chevron-up"></span></a>
                                {%endif%}
                            </div>


                    {%endif%}
                    <section class="panel panel-default padding-0">
                    <header class="panel-heading">
                        <!--<i data-title="" data-placement="bottom" data-toggle="tooltip" class="fa fa-info-sign text-muted" data-original-title="" title=""><i class="fa fa-question-circle"></i></i>-->

                        {% if breadcrumb|length == 0%} [ {% if position %} <a href="/center/publish" class="text-info">全部</a>{%else%}<strong>全部</strong>{%endif%}
                        {%for key ,val in config.setup.DOCUMENT_POSITION %} {%if position != key %}<a href="/center/publish/index/?position={{key}}"
                                                                                                          class="text-info">{{val}}</a>{%else%}<strong>{{val}}</strong>{% endif %}&nbsp; {% endfor
                        %}] {%endif%} {%if model|length > 1 %}[ 模型：{%if model_id ==null %}<strong>全部</strong>{%else%}
                        <a
                                href="/center/publish/index/?pid={{pid}}&cate_id={{cate_id}}" class="text-info"> 全部 </a>{%endif%}&nbsp; {% for val in modellist%} {% if model_id != val.id %}<a href="/center/publish/index/?model_id={{val.id}}&pid={{pid}}&cate_id={{cate_id}}"
                                                                                                                                                                                              class="text-info">{{val.title}}</a>{% else %}<strong>{{val.title}}</strong>{% endif %}&nbsp;
                        {% endfor %} ]{% endif %} {% if groups %}[ 分组：{%if group_id ==0 %}<strong>全部</strong>{%else%}
                        <a
                                href="/center/publish/index/?pid={{pid}}&cate_id={{cate_id}}"  class="text-info">全部</a>{%endif%} {%for key ,val in groups %} {% if group_id != key %}<a href="/center/publish/index/?pid={{pid}}&cate_id={{cate_id}}&group_id={{key}}&sortid={{sortid}}"  class="text-info">{{val}}</a>{%
                        else %}<strong>{{val}}</strong>{% endif %}&nbsp; {% endfor %} ]{% endif %}
                    </header>
                    <div class="row wrapper padding-10">

                        <div class="col-sm-9 m-b-xs">
                            <div class="">
                                <div class="btn-group">
                                    <button {%if model|length> 1 %} data-toggle="dropdown" {% endif %} class="btn btn-info btn-sm document_add
                                        dropdown-toggle {% if allow == 0 %}disabled{% endif %}" {%if model|length
                                        == 1 %} url="/center/publish/add/?model_id={{modellist[0].id}}&pid={{pid}}&cate_id={{cate_id}}&group_id={{group_id}}&sortid={{sortid}}"{%endif%}
                                        >发布内容 {%if model|length > 1 %}<span class="caret"></span>{% endif %}</button>
                                    {%if model|length > 1 %}
                                    <ul class="dropdown-menu">

                                        {% for val in modellist%}
                                        <li> <a href="/center/publish/add/?model_id={{val.id}}&pid={{pid}}&cate_id={{cate_id}}&group_id={{group_id}}&sortid={{sortid}}"
                                                class="text-info">添加{{val.title}}</a></li>
                                        {% endfor %}

                                        <!--<li class="divider"></li>-->
                                        <!--<li><a href="#">添加内容</a></li>-->
                                    </ul>
                                    {% endif %}
                                </div>
                                {#
                                <div class="btn-group">
                                    <a class="btn btn-sm btn-info ajax-post confirm" target-form="ids" href="#" style="line-height: 1.5">
                                        已审核
                                    </a>
                                    <a class="btn btn-sm btn-info ajax-post confirm" target-form="ids" href="#" style="line-height: 1.5">
                                        待审核
                                    </a>
                                    <a class="btn btn-sm btn-info ajax-post confirm" target-form="ids" href="#" style="line-height: 1.5">
                                        未通过
                                    </a>
                                </div>
                                #}
                            </div>
                        </div>
                        <div class="col-sm-3">
                            <div class="input-group pull-right search-form">
                                <input type="text" class="input-sm form-control" name="{{model.search_key|default('title', true)}}" placeholder="请输入关键字"
                                       value="{{controller.get('title')}}" style="height: auto">
                                <span class="input-group-btn">
                        <button class="btn btn-sm btn-default" type="button" id="search" url="/admin/cms/list/model/{{model.name}}">搜索</button>
                      </span>
                            </div>
                        </div>
                    </div>
                    <div class="table-responsive">
                        <table class="table table-striped b-t b-light">
                            <thead>
                            <tr>
                                {#
                                <th style="width:20px;">
                                    <label class="checkbox m-n i-checks">
                                        <input type="checkbox"><i></i></label>
                                </th>
                                #}
                                {% for field in list_grids %}
                                <th>{{field.title}}</th>
                                {% endfor %}
                            </tr>
                            </thead>
                            <tbody>
                            {% for data in list %}
                            <tr>
                                {#
                                <td>
                                    <label class="checkbox m-n i-checks">
                                        <input class="ids" type="checkbox" name="ids" value="{{data.id}}"><i></i></label>
                                </td>
                                #}
                                {% for grid in list_grids %}
                                <td>{{data|get_list_field(grid,ctx.controller)| safe}}</td>
                                {% endfor %}
                            </tr>
                            {% else %}
                            <tr>
                                <td colspan="{{list_grids|length + 1}}">
                                    <div class="alert alert-warning alert-block">
                                        <button data-dismiss="alert" class="close" type="button">×</button>
                                        <p>This would display if the 'item' collection were empty</p>
                                    </div>
                                </td>
                            </tr>

                            {% endfor %}


                            </tbody>
                        </table>
                    </div>
                    <footer class="panel-footer">
                        <div class="row">
                            {#
                            <div class="col-md-3">
                                <div class="btn-group">
                                    <a class="btn btn-sm btn-default ajax-post confirm" target-form="ids" href="#">
                                        微信图文
                                    </a>
                                    <a class="btn btn-sm btn-default ajax-post confirm" target-form="ids" href="#">
                                        高级图文
                                    </a>
                                    <a class="btn btn-sm btn-default ajax-post confirm" target-form="ids" href="#">
                                        推送
                                    </a>
                                </div>
                            </div>
#}
                            <div class="col-md-12 text-right text-center-xs">
                                {{pagerData | safe}}
                            </div>
                        </div>
                    </footer>
                </section></div>
            </div>
        </div>

</div>

    </div>
</section>
<!-- / -->
{% endblock %}
{% block script %}
<script src="/static/admin/js/zTree/jquery.ztree.core-3.5.min.js" type="text/javascript"></script>
<script type="text/javascript">
    <!--
    var zTree;
    var demoIframe;

    var setting = {
        async: {
            enable: true,
            url: "/center/publish/getmenu",
        },
        view: {
            showLine: true,
            selectedMulti: false,
        },
        callback: {
            onAsyncSuccess: zTreeOnAsyncSuccess

        }
    };

    function zTreeOnAsyncSuccess(event, treeId, treeNode, msg) {
        // console.log(treeNode)
        var treeObj = $.fn.zTree.getZTreeObj(treeId);
        treeObj.expandAll(true);
        var id= $("#"+treeId).attr("data-cate");
        console.log(id);
        curMenu = treeObj.getNodeByParam("id", id, null);
        console.log(treeId)
        treeObj.selectNode(curMenu);
    };
    function expandNode(e) {
        var zTree = $.fn.zTree.getZTreeObj("tree"),
                type = e.data.type,
                nodes = zTree.getSelectedNodes();
        if (type == "expandAll") {
            zTree.expandAll(true);
        } else if (type == "collapseAll") {
            zTree.expandAll(false);
        }
    }


    //-->
    $(function(){
        var t = $("#tree");
        t = $.fn.zTree.init(t, setting).expandAll(true);
        $("#expandAllBtn").bind("click", {type:"expandAll"}, expandNode);
        $("#collapseAllBtn").bind("click", {type:"collapseAll"}, expandNode);
        //搜索功能
        $("#search").click(function(){
            var url = $(this).attr('url');
            var query  = $('.search-form').find('input').serialize();
            query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
            query = query.replace(/^&/g,'');
            if( url.indexOf('?')>0 ){
                url += '&' + query;
            }else{
                url += '?' + query;
            }
            window.location.href = url;
        });

        //回车自动提交
        $('.search-form').find('input').keyup(function(event){
            if(event.keyCode===13){
                $("#search").click();
            }
        });

        //只有一个模型时，点击新增
        $('.document_add').click(function(){
            var url = $(this).attr('url');
            if(url != undefined && url != ''){
                window.location.href = url;
            }
        });
    })

</script>
{% endblock %}}